// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Plasma Ball Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 80 : TYPE_PLASMABALL


// Static Values

// Tables
private table PlasmaBall_table0
	0, 8, 1, 9, 6, 7, 0, 8, 1, 9, 6, 7, 2, 3, 4, 5
end table

private table PlasmaBall_table1
	6, 1, 7, 1
end table

event ObjectMain
	switch object.state
	case 0
		object.value4 = PlasmaBall_table0
		object.value2 = 63
		object.value3 = 2
		object.xvel = object.value1
		object.xvel -= object.xpos
		object.xvel >>= 4
		object.state++
		break
	case 1
		if object.alpha < 192
			object.alpha += 16
		end if
		object.xpos += object.xvel
		if object.xpos <= object.value1
			object.value0 = 180
			object.state++
		end if
		break
	case 2
		object.value0--
		if object.value0 <= 0
			object.animationTimer = 0
			object.alpha = 128
			object.value4 = PlasmaBall_table1
			object.value2 = 7
			object.value3 = 1
			object.xvel = object[0].xpos
			object.xvel -= object.xpos
			object.xvel >>= 8
			object.yvel = 0x14000
			object.value0 = 133
			object.state++
		end if
		break
	case 3
		object.xpos += object.xvel
		object.ypos += object.yvel
		object.value0--
		if object.value0 <= 0
			object.type = TypeName[Blank Object]
		end if
		break
	end switch
	object.animationTimer++
	object.animationTimer &= object.value2
	temp0 = object.animationTimer
	temp0 >>= object.value3
	GetTableValue(object.frame, temp0, object.value4)
	if object.value4 == PlasmaBall_table1
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -12, -12, 12, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_LightningHit)
			end if
		next
	end if
end event


event ObjectDraw
	if object.value4 == PlasmaBall_table1
		DrawSpriteXY(object.frame, object.xpos, object.ypos)
		DrawSpriteFX(5, FX_INK, object.xpos, object.ypos)
	else
		DrawSpriteFX(object.frame, FX_INK, object.xpos, object.ypos)
	end if
end event


event ObjectStartup
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-16, -16, 32, 32, 2, 397)
	SpriteFrame(-12, -12, 24, 24, 35, 397)
	SpriteFrame(-5, -5, 10, 10, 60, 397)
	SpriteFrame(-7, -7, 14, 14, 71, 397)
	SpriteFrame(-8, -8, 16, 16, 86, 397)
	SpriteFrame(-12, -12, 24, 24, 103, 397)
	SpriteFrame(-7, -7, 14, 15, 128, 397)
	SpriteFrame(-7, -7, 14, 15, 145, 397)
	SpriteFrame(-16, -16, 32, 32, 2, 430)
	SpriteFrame(-12, -12, 24, 24, 35, 430)
	foreach (TypeName[Plasma Ball], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].inkEffect = INK_ADD
		object[arrayPos0].alpha = 128
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
